package ru.osu.acm.common.entities;

import ru.osu.acm.testing.Utils;

import java.util.Date;

/**
 * User: aleksey
 * Date: Oct 1, 2009
 * Time: 10:56:24 PM
 */
public class Message {
    private int id;
    private Team team;
    private Person person;
    private Contest contest;
    private Problem problem;
    private boolean incoming;
    private String message;
    private Date received;

    public Message(int id, Team team, Person person, Contest contest, Problem problem, boolean incoming, String message, Date received) {
        this.id = id;
        this.team = team;
        this.person = person;
        this.contest = contest;
        this.problem = problem;
        this.incoming = incoming;
        this.message = message;
        this.received = received;
    }

    public String getUser() {
        if (incoming) {
            return "Administrator";
        }
        if (team != null) {
            return team.getTeamname();
        }
        return person.getName() + " " + person.getSurname();
    }

    public Integer getTeamId() {
        if (team != null) {
            return team.getId();
        }
        return -1;
    }

    public Integer getPersonId() {
        if (person != null) {
            return person.getId();
        }
        return -1;
    }

    public String getMessageHtml() {
        return Utils.prepareSourceForHtml(message);
    }

    public String getMessagePart() {
        return Utils.prepareSourceForHtml(message.substring(0, 60).replace('\n', ' '));
    }

    public String getStyle() {
        if (incoming) {
            return "commoncontaineradmin";
        }
        return "commoncontainer";
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public Team getTeam() {
        return team;
    }

    public void setTeam(Team team) {
        this.team = team;
    }

    public Person getPerson() {
        return person;
    }

    public void setPerson(Person person) {
        this.person = person;
    }

    public Contest getContest() {
        return contest;
    }

    public void setContest(Contest contest) {
        this.contest = contest;
    }

    public Problem getProblem() {
        return problem;
    }

    public void setProblem(Problem problem) {
        this.problem = problem;
    }

    public boolean isIncoming() {
        return incoming;
    }

    public void setIncoming(boolean incoming) {
        this.incoming = incoming;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Date getReceived() {
        return received;
    }

    public void setReceived(Date received) {
        this.received = received;
    }
}
